/*
 * @(#)com.cloud.food.controller 2020-01-05 00:27
 * @Author <a href="mailto:xyqierkang@gmail.com">ErKang Qi</a>
 * @Blog：https://www.qekang.com
 * Copyright (c) 2019-2020 Shanghai
 * All rights reserved.

 * This software is the confidential and proprietary information of
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 */
package com.cloud.lan.api;

import com.cloud.lan.entity.base.BaseResponse;
import com.cloud.lan.service.aliyun.AliyunService;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 文件上传 控制器
 * @author ErKang
 * @date Created in 2021/12/12 23:34
 * @title FileUploadApi.java
 * Department: Product development
 */
@RestController
@RequestMapping(value = {"/v1/manage/file/"}, method = {RequestMethod.GET, RequestMethod.POST}, consumes = {"*/*"}, produces = {"application/json"})
public class FileUploadApi {

    @Resource
    private AliyunService aliyunService;

    @RequestMapping(value = "upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public BaseResponse<Object> upload(@RequestPart(value = "file") MultipartFile file) {
        String url = aliyunService.upload(file);
        return BaseResponse.success(url);
    }

    @GetMapping("uploadJson")
    @ResponseBody
    public BaseResponse<Object> uploadJson(String fileName, String content) {
        String url = aliyunService.uploadJson(fileName, content);
        return BaseResponse.success(url);
    }
}
